.TH std::filesystem::path::remove_filename 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::filesystem::path::remove_filename \- std::filesystem::path::remove_filename

.SH Synopsis
   path& remove_filename();  \fI(since C++17)\fP

   Removes a single generic-format filename component (as returned by filename) from
   the given generic-format path.

   After this function completes, has_filename returns false.

.SH Parameters

   \fI(none)\fP

.SH Return value

   *this

.SH Exceptions

   May throw implementation-defined exceptions.

.SH Example


// Run this code

 #include <filesystem>
 #include <iostream>
 namespace fs = std::filesystem;

 int main()
 {
     fs::path p;
     std::cout << std::boolalpha
               << (p = "foo/bar").remove_filename() << '\\t' << p.has_filename() << '\\n'
               << (p = "foo/").remove_filename() << '\\t' << p.has_filename() << '\\n'
               << (p = "/foo").remove_filename() << '\\t' << p.has_filename() << '\\n'
               << (p = "/").remove_filename() << '\\t' << p.has_filename() << '\\n'
               << (p = "").remove_filename() << '\\t' << p.has_filename() << '\\n';
 }

.SH Output:

 "foo/"  false
 "foo/"  false
 "/"     false
 "/"     false
 ""      false

.SH See also

   filename         returns the filename path component
                    \fI(public member function)\fP
   replace_filename replaces the last path component with another path
                    \fI(public member function)\fP
   has_filename     checks if the corresponding path element is not empty
                    \fI(public member function)\fP
